﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cysharp.Threading.Tasks;
using System;
using UnityEngine.Networking;
using TMPro;

public class UniTaskDemo : MonoBehaviour
{
    public TextMeshProUGUI UGUIText;
    public string[] Urls;

    // Start is called before the first frame update
    async UniTaskVoid Start()
    {
        await UniTask.Delay(TimeSpan.FromSeconds(3.0f));
        Debug.Log("UniTask.Delay 等待3000毫秒后执行");

        await UniTask.DelayFrame(300);
        Debug.Log("UniTask.DelayFrame 等待300帧后执行");

        var text = (await UnityWebRequest.Get(Urls[0]).SendWebRequest()).downloadHandler.text;
        Debug.Log($"异步下载资源成功，请看UI界面显示内容");

        await UniTask.SwitchToMainThread();
        UGUIText.text = text;

        //是yield return new WaitForFixedUpdate()的替代方法
        await UniTask.WaitForFixedUpdate();
    }

    // Update is called once per frame
    void Update()
    {

    }
}
